package ui;

import java.util.List;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Composite;

import each_class.RanKingClass;

public class MusicStationUI extends AbstractUI {

	private MusicListView officialMusicList;
	private MusicListView recommendMusicList;
	private TabFolderItem musicItem;
	private TabFolderItem musicListItem;
	public static Thread thread = null;

	public MusicStationUI(Composite parent, int style) {
		super(parent, style);
		
		title.setText("音乐馆");
		officialMusicList = new MusicListView(this, SWT.NONE);
		officialMusicList.setBounds(0, 123, 1210, 513);
		recommendMusicList = new MusicListView(this, SWT.NONE);
		recommendMusicList.setBounds(0, 123, 1210, 513);
		musicItem =  new TabFolderItem(tabFolder, officialMusicList);
		musicListItem =  new TabFolderItem(tabFolder, recommendMusicList);
		tabFolder.setFont(new Font(getDisplay(), "Microsoft YaHei UI", 18, SWT.NORMAL));
		musicItem.setText("官方歌单");
		musicListItem.setText("推荐歌单");
		tabFolder.setCurrentTabFolderItem(musicItem);
		tabFolder.getCurrentTabFolderItem().active();
		tabFolder.layout();
		isLoad = true;
		thread = new Thread() {
			public void run() {
				Map<String, List<RanKingClass>> data = ui.global.Operation.getMusicStation();
				isLoad = false;
				getDisplay().asyncExec(new Runnable() {
					
					@Override
					public void run() {
						initail(data);
						layout();
					}
				});
			};
		};
		thread.start();
	}

	public void initail(Map<String, List<RanKingClass>> data) {
		officialMusicList.dispose();
		recommendMusicList.dispose();
		officialMusicList = new MusicListView(this, SWT.NONE);
		officialMusicList.setBounds(0, 123, 1210, 513);
		musicItem.setView(officialMusicList);

		recommendMusicList = new MusicListView(this, SWT.NONE);
		musicListItem.setView(recommendMusicList);
		recommendMusicList.setBounds(0, 123, 1210, 513);
		officialMusicList.loadMusicList(data.get("官方歌单"));

		recommendMusicList.loadMusicList(data.get("推荐歌单"));

	}

	@Override
	public void active() {
		setVisible(true);
	}

}
